/*
 * Description: performance pipe reciever
 */
#ifndef PERF_PIPE_RECIEVER_H
#define PERF_PIPE_RECIEVER_H
#include <Windows.h>
#include <tchar.h>
#include "singleton.h"
#include "rpc_service/sendto_host.h"
#include "performance/model/perf_info.h"

constexpr auto BUFSIZE = 512;
constexpr auto PIPE_NAME = R"(\\.\PIPE\PERF_COMM)";

namespace PERF {
class PerfPipeReciever {
public:
    int Init(std::shared_ptr<WINCONTROL::SendToHost> sendtoHost);
    void CreatePipe(HANDLE &hPipe);
    int RecvMessage();

private:
    static DWORD ProcessMessage(HANDLE);
    static BOOL HandleMessage(const std::string &);
    static BOOL ParseMessage(const std::string &message, std::shared_ptr<PerfInfo> perfInfo);
    static BOOL GetSecurityAttributes(SECURITY_ATTRIBUTES &sa);
};
#define PERF_PIPE_RECIEVER SingletonNew<PERF::PerfPipeReciever>::GetInstance()
}  // namespace PERF
#endif